<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>处理更新</title>
</head>
<body>
<h2>处理更新</h2>
<%
    request.setCharacterEncoding("utf-8");

    int id= Integer.parseInt(request.getParameter("id"));
    String name=request.getParameter("name");
    String sex=request.getParameter("sex");
    int age= Integer.parseInt(request.getParameter("age"));
    float weight= Float.parseFloat(request.getParameter("weight"));
    float height= Float.parseFloat(request.getParameter("height"));
    int idselect= (int) session.getAttribute("idselect");
    String username = "root";
    String pwd = "pengfei";
    String driverName = "com.mysql.jdbc.Driver";
    String dbName = "student";
    String url = "jdbc:mysql://127.0.0.1:3306/" + dbName + "?user=" + username + "&password=" + pwd + "&useUnicode=true&characterEncoding=UTF-8";
    String sql="update stu_info set id=?,name=?,sex=?,age=?,weight=?,height=? where id=?";
    Connection connection = null;
    ResultSet rs = null;
    PreparedStatement st = null;
    try {
        Class.forName(driverName);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    try {
        connection= DriverManager.getConnection(url);
        PreparedStatement pst=connection.prepareStatement(sql);
        pst.setInt(1,id);pst.setString(2,name);pst.setString(3,sex);
        pst.setInt(4,age);pst.setFloat(5,weight);pst.setFloat(6,height);
        pst.setInt(7,idselect);
        int n=pst.executeUpdate();
        if(n>=1)
        {
            out.print("重写数据成功！！");
        }
        else
        {
            out.print("重写失败！！");
        }
        if(pst!=null) pst.close();
        if(connection!=null) connection.close();

    } catch (SQLException e) {
        e.printStackTrace();
    }


%>
</body>
</html>
